﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WF_QLThuVien.Utilities;
using WF_QLThuVien.Entities;
using WF_QLThuVien.DataLayer;
using System.Data;

namespace WF_QLThuVien.DataLayer
{
    public class CDAL_Login
    {
        DataAccessHelper db = new DataAccessHelper();

        public CLogin LoadUser() 
        {
            try
            {
                string cmd = "SELECT * FROM DangNhap WHERE ID='123'";
                DataTable dt = db.GetDataTable(cmd);
                if (dt.Rows.Count > 0)
                {
                    CLogin li = new CLogin(dt.Rows[0]);
                    return li;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Lỗi CAL_Login.\n" + ex.ToString());
            }
        }

        public bool Update(CLogin li)
        {
            try
            {
                string cmd = "UPDATE DangNhap SET"
                + " User='" + li.User + "',"
                + " Pass='" + li.Pass + "'";
                //+ " WHERE ID='123'";
                db.ExecuteNonQuery(cmd);
                return true;
            }
            catch (Exception ex)
            {
                throw new Exception("Lỗi CDAL_Login.Update \n" + ex.ToString());
            }
        }
    }
}
